package ee.serge.util.bootstrap;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Grid;

public class BTable extends Grid {

   public static final String DEFAULT = "z";
   public static final String ZEBRA_STRIPED = "zebra-striped";
   
   public BTable(int rows, int cols, String style) {
      super(rows, cols);
      setStyleName("tbl");
      addStyleName(style);
   }
   
   public BTable(int rows, String[] headers) {
      this(rows, headers, DEFAULT);
   }
   
   public BTable(int rows, String[] headers, String style) {
      super(rows, headers.length);
      setStyleName("tbl");
      addStyleName(style);
      
      // use DOM to create thead element.... 
      Element thead = DOM.createElement("thead");
      Element tr = DOM.createTR();

      // add columns 
      DOM.appendChild(thead,tr);
      for (int k = 0; k < headers.length; k++) {
         Element th = DOM.createTH();
         DOM.appendChild(tr,th); // add some text to the header...
         DOM.setInnerText(th, headers[k]); 
      }

      // get the table element
      Element table = this.getElement();

      // and add the thead before the tbody
      DOM.insertChild(table,thead,0); 
   }
   
   public void setText(int row, int col, long l) {
      super.setText(row, col, String.valueOf(l));
   }
   
}
